//console.log('hello');
var app = angular.module('myApp');
app.controller('f-controller',['$scope','$http','$timeout',function($scope,$http,$timeout){
	$http.get("find/js/find.json").success(function (res){
//		console.log(res.data.infos);
		$scope.data = res.data.infos;
		$scope.more_works = '更多';
		
	});
	$http.get("find/js/find2.json").success(function (res){
//		console.log(res.data);
		$scope.data2 = res.data;
		
		
	});
	
	$timeout(function(){
		var ASwiper = new Swiper('#f-all-wrap',{
			
		});
		var swiper = new Swiper('#f-banner-wrap',{
			direction: 'horizontal',
			loop: true,
			autoplay:3000,
			observer: true,
			autoplayDisableOnInteraction: false,
			pagination: '.swiper-pagination',
		});
		var swiper2 = new Swiper('#f-more-works-wrap',{
			
		});
		//获取f-all-wrapper
		var f_all_wrap = document.querySelector('#f-all-wrap');
		var f_all_wrapper = document.querySelector('#f-all-wrapper');
		var f_all_works = document.querySelector('#f-all-works');
		var w = f_all_wrapper.offsetWidth;
		
		//绑定排行榜链接
		var tag_a = document.querySelectorAll('.f-banner-pic a');
		for(let i = 0 ; i < tag_a.length;i++){
			tag_a[i].href = "./find/demo" + (i+1) + ".html";
		};
		tag_a[3].href = "";
		tag_a[3].onclick = function(){
			f_all_wrapper.style.transform = 'translate3d(-' + w + 'px,0px,0px)';
			document.querySelector('#slide2').scrollTop = 0;
		};
		f_all_works.onclick = function(){
			f_all_wrapper.style.transform = 'translate3d(-' + w + 'px,0px,0px)';
			document.querySelector('#slide2').scrollTop = 0;
		}
		//获取分类页面类别li
		var class_lis = document.querySelectorAll("#title-wrap li");
		var f_more_works_wrapper = document.querySelector('#f-more-works-wrapper');
//		console.log(class_lis);
		class_lis[0].style.borderBottom = '3px solid yellow';
		
//		f_more_works_wrapper.addEventListener('touchstart',function(){
//			console.log('触摸开始');
//		});
//		f_more_works_wrapper.addEventListener('touchmove',function(){
//			console.log('正在滑动');
//		});
		f_more_works_wrapper.addEventListener('touchend',function(){
//			console.log('触摸结束');
			
			setTimeout(function(){
				var moveLength = parseInt(f_more_works_wrapper.style.transform.split('(')[1].split(',')[0]);
				var index = parseInt(-1 * moveLength / w);
				for(var i = 0; i < class_lis.length; i++){
					class_lis[i].style.borderBottom = 'none';
				}
				class_lis[index].style.borderBottom = '3px solid yellow';
			},300)
			
			
		});
		
		function checkWidth(){
			
		}
		
		
		
	},1000);
//	$scope.$watch('$viewContentLoaded', function(){
//		console.log('加载完毕');
//		
//	});
		
	
	
}]);



